package com.ssyt.yt1.day10.factory;

interface Phone {

	void printName();
}

class Samsung implements Phone {

	@Override
	public void printName() {
		System.out.println("Samsung...");
	}
}

class Xiaomi implements Phone {

	@Override
	public void printName() {
		System.out.println("Xiaomi...");
	}
}

class Smartisan implements Phone {

	@Override
	public void printName() {
		System.out.println("Smartisan...");
	}
}

class Apple implements Phone {

	@Override
	public void printName() {
		System.out.println("Apple...");
	}
}

/**
 * 工厂去生产手机（工厂去跟手机公司打交道）
 * 
 * @author Administrator
 *
 */
class Factory {

	public static Phone getPhone(String phoneName) {
		Phone phone = null;
		if ("Samsung".equals(phoneName)) {
			phone = new Samsung();
		}
		if ("Xiaomi".equals(phoneName)) {
			phone = new Xiaomi();
		}
		if ("Smartisan".equals(phoneName)) {
			phone = new Smartisan();
		}
		if ("apple".equals(phoneName)) {
			phone = new Apple();
		}
		return phone;
	}
}

/**
 * 工厂设计模式：解决了不需要用户直接跟手机公司打交道的问题！
 * 
 * @author Administrator
 *
 */
public class FactoryDemo {

	public static void main(String[] args) {
		Phone phone = Factory.getPhone("Xiaomi");
		if (phone == null) {
			System.out.println("不存在此手机！");
		} else {
			phone.printName();
		}
	}
}
